package com.example.demo.controller;

import com.example.demo.entity.Open;
import com.example.demo.mapper.OpenMapper;
import com.example.demo.service.LoginService;
import com.example.demo.utils.HttpGetUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Login {

//    private LoginService loginService;

    @Autowired
    private OpenMapper openMapper;


    @RequestMapping("/login")
    public Open  Login(String code){
        HttpGetUtils httpGetUtils=new HttpGetUtils();
        String openid=httpGetUtils.doget(code);
        System.out.println(openid);
        Open open=new Open();
        if(openid!=null){
            open =openMapper.findOpenid(openid);

            if(open.getOpenid()==null){
                open.setOpenid(openid);
                open.setAge(20);
                open.setOpenname("在编辑");
                open.setIndroduction("我不断地完善自己，提高自身素质。我在学好专业课与公共课的基础上，还阅读了超多的课外书籍，不断地增加新知识，陶冶情操开拓视野。不仅仅仅如此，我还用心参加社会实践活动，和各种文体活动，培养了我务必的组织与社交潜力。本人热爱羽毛球篮球跑步下棋唱歌;在性格方面：性格开朗，外向的小伙子学习刻苦认真，成绩优秀，为人诚实守信，有很强的职责感，有团队意识和合作精神，吃苦耐劳，此刻我拥有年轻和知识，我能够用热情和活力，自信和学识来克服毕业后生活和工作的各种困难，用自己的学习潜力和分析处理问题的协调，管理潜力去完成今后美丽的人生。");
                open.setStudentid("201835020821");
                open.setStudentname("lja");
                open.setSex("男");
                open.setHeight("178cm");
                open.setCourse("软工8班");
                open.setGrade("2018级");
                openMapper.InsertOpen(open);
            }
            System.out.println(open);
        }
        return open;
    }

}
